package com.example.opengl.player.decoder

import android.media.MediaCodec
import android.media.MediaFormat
import android.view.Surface
import com.example.opengl.player.base.BaseDecoder
import com.example.opengl.player.base.IExtractor
import com.example.opengl.player.extractor.VideoExtractor
import java.nio.ByteBuffer

class VideoDecoder(path:String, surface: Surface): BaseDecoder(path) {
    private val mSurface = surface
    override fun doneDecode() {

    }

    override fun render(outputBuffer: ByteBuffer, bufferInfo: MediaCodec.BufferInfo) {

    }

    override fun configCodec(codec: MediaCodec, format: MediaFormat): Boolean {
       if (check()){
           codec.configure(format,mSurface,null,0)
           notifyDecode()
           return true
       }
        return false
    }

    override fun initSpecParams(format: MediaFormat) {
    }

    override fun initRender(): Boolean = true

    override fun check(): Boolean {
        if (mSurface == null){
             mStateListener?.decoderError(this,"Surface is null")
            return false
        }
        return true
    }

    override fun initExtractor(path: String): IExtractor = VideoExtractor(path)
}